<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import Edit from "../edit/home/index.js";
import EditRuleHomeDialog from "../edit/rule/home/index.js";
export default {
  mixins: [
    Vue.prototype.$vFN.Mixins.Base,
    Vue.prototype.$vFN.Mixins.Page,
    Vue.prototype.$vFN.Mixins.Table,
  ],
  components: {},
  data() {
    return {
      appWindow: window,
      moreSearchShow: false,
      // 页面接口地址
      apiUrl: {
        list: "mall-site-portal/member-rights/list",
        delete: "mall-site-portal/member-rights/delete",
        update: "mall-site-portal/member-rights/update",
        detail: "mall-site-portal/member-rights/getItem",
      },

      isIndeterminate: false,
      checkAll: false,

      mixinTable_tableSearchData: {
        name: "",
      },
      // 表格数据
      // tableData: [],
      // 表格数据删除展示结构
      tableDeleteConfig: {
        title: "确定删除?",
        columns: [
          {
            label: "权益名称",
            prop: "rightName",
            type: "",
          },
          {
            label: "权益类型",
            prop: "rightType",
            type: "",
          },
          {
            label: "是否显示",
            prop: "isOpen",
            type: "state-icon",
            options: {
              success: 1,
              error: 0,
            },
          },
        ],
      },
    };
  },
  methods: {
    // 打开添加/修改
    editBoxOpen(params_) {
      Edit.init({
        mixinEdit_parent: this,
        mixinEdit_editType: params_.type,
        rightType: params_.rightType,
        id: params_.id,
      });
    },
    // 初始化
    init() {
      // 刷新表格数据，此方法扩展时可重写
      this.mixinTable_refreshData();
    },

    // 开关改变
    async statusChange(params__) {
      this.mixinTable_loading = true;
      let response = await this.getDetail(params__.id);

      console.log(response);
      const { remark, rightType, rightName } = response.data;

      let res = await this.$vFN.Http.post(
        {
          url: this.apiUrl.update,
          data: {
            id: params__.id,
            remark: remark,
            rightName: rightName,
            rightType: rightType,
            isOpen: params__.isOpen,
          },
        },
        window
      );
      this.mixinTable_loading = false;
      if (res._ok) {
        this.$vFN.Tools.messageSuccess(res.message);
        this.mixinTable_refreshData();
      }
    },

    // 获取权益详情
    async getDetail(_id) {
      let res = await this.$vFN.Http.post(
        {
          url: this.apiUrl.detail,
          data: {
            id: _id,
          },
        },
        window
      );

      return res;
    },

    // 设置规则
    setRule(params_) {
      EditRuleHomeDialog.init({
        rightId: params_.id,
      });
    },
  },
  watch: {},
  mounted() {
    this.init();
  },
  activated() {},
  filters: {
    getType(type) {
      if (type == 1) {
        return "商品折扣";
      } else if (type == 2) {
        return "订单折扣";
      } else if (type == 3) {
        return "运费减免";
      } else if (type == 4) {
        return "自定义";
      }
    },
  },
};
</script>
